package com.zhanglijie.base.threadPool;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author zhanglijie
 * @version 1.0
 * @since 1.1.0 2022/7/5 0005 0:20
 */
public class CoreThreadNumDemo2 {
    static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(2,4,1, TimeUnit.NANOSECONDS,new LinkedBlockingQueue<>( ));

    public static void main(String[] args) throws InterruptedException {
        threadPool.allowCoreThreadTimeOut(true);//默认false

        for (int i = 0; i < 10; i++) {
            threadPool.submit(()->{
                System.out.println(Thread.currentThread().getName()+"   ===>执行了");
            });
        }
        Thread.sleep(10000);
        System.out.println("现在核心线程数量===>"+threadPool.getPoolSize());
    }
}
